//
//  NewCityDynamicListCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/9/12.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit
import SDWebImage

class NewCityDynamicListCell: BaseTableViewCell {
    @IBOutlet weak var bigBgView: UIView!
    
    @IBOutlet weak var topBgView: UIView!
    @IBOutlet weak var lineView: UIView!
    @IBOutlet weak var timeBgView: UIView!
    
    @IBOutlet weak var bgView: UIView!
    @IBOutlet weak var bottomMarTwo: NSLayoutConstraint!
    @IBOutlet weak var bottomMargFirst: NSLayoutConstraint!
    @IBOutlet weak var imageViewH: NSLayoutConstraint!
    
    @IBOutlet weak var bottomMarThree: NSLayoutConstraint!
    @IBOutlet weak var topImageView: UIImageView!
    @IBOutlet weak var timeLabel: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    
    @IBOutlet weak var desLabel: UILabel!
    var model : NewCityDynamicModel? {
        
        didSet{
            
            if model == nil {
                return
            }
            
            if let imageCach = SDWebImageManager.shared().imageCache {
                
                if let tempImage = imageCach.imageFromDiskCache(forKey: model?.message_cover)  {
                    
                    imageViewH.constant = tempImage.size.height / tempImage.size.width * (KScreenW - 60)
                    
                    
                    topImageView.image = tempImage
                    
                }else{
                    
                    imageViewH.constant = (KScreenW - 60) / 16 * 9
                    
                    topImageView.sd_setImage(with: URL(string :model!.message_cover), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                        
                    }
                    
                }
                
                
                
            }else{
                
                
                imageViewH.constant = (KScreenW - 60) / 16 * 9
                
                topImageView.sd_setImage(with: URL(string :model!.message_cover), placeholderImage: UIImage.defaulImage(), options: .progressiveDownload) { (image, _, _, _) in
                    
                }
                
                
            }
            
            
            
            timeLabel.text = model?.message_time
            
            titleLabel.text = model?.message_title
            
            desLabel.text = model?.message_desc
            
            
            
            
        }
        
    }

    override func awakeFromNib() {
        super.awakeFromNib()
//        contentView.backgroundColor = UIColor.white
        bgView.addCornerAndBorder(borderColor: UIColor.gray, borderWidth: 0.6, masksToBounds: true, cornerRadius: 5)
        bgView.backgroundColor = UIColor.white
        bigBgView.backgroundColor = UIColor.viewBgGrey()
        topBgView.backgroundColor = UIColor.viewBgGrey()
        timeBgView.addCornerAndBorder(borderColor: nil, borderWidth: 0, masksToBounds: true, cornerRadius: 3)
        timeLabel.textColor = UIColor.white
        desLabel.textColor = UIColor.dakGray()
        lineView.backgroundColor = UIColor.lineGray()
        bottomMargFirst.constant = 0
        bottomMarTwo.constant = 0
        bottomMarThree.constant = 0

    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
